package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mysql.jdbc.StringUtils;
import com.project.entity.Business;
import com.project.entity.Rider;
import com.project.mapper.TRiderMapper;
import com.project.service.IRiderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangyang
 * @since 2021-10-06
 */
@Service
public class TRiderServiceImpl extends ServiceImpl<TRiderMapper, Rider> implements IRiderService {

    @Autowired
    private TRiderMapper riderMapper;

    @Override
    public List<Rider> findByItem(String name, String sex, LocalDate start, LocalDate end) {
        QueryWrapper<Rider> wrapper = new QueryWrapper<>();
        if (!StringUtils.isNullOrEmpty(name)){
            wrapper.like("r_name",name);
        }
        if (!StringUtils.isNullOrEmpty(sex)){
            wrapper.eq("r_sex",sex);
        }
        if (start != null){
            wrapper.ge("r_time",start);
        }if (end != null){
            wrapper.le("r_time",end);
        }
        return riderMapper.selectList(wrapper);
    }

    @Override
    public Rider findById(String id) {
        QueryWrapper<Rider> wrapper = new QueryWrapper<>();
        wrapper.eq("r_code",id);
        return riderMapper.selectOne(wrapper);
    }
}
